package com.example.uploadfilestoserver;

import com.mreko.dashupload.ServerCommunicateUtil;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {
	private Button button;
	private UploadFile uploadFile;
	private Button download;
	private Button response;
	private EditText editText, fileText;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		button = (Button) findViewById(R.id.button);
		download = (Button) findViewById(R.id.download);
		response = (Button) findViewById(R.id.response);
		editText = (EditText) findViewById(R.id.uploadUrl);
		fileText = (EditText) findViewById(R.id.file);
		editText.setText("http://pilatus.d1.comp.nus.edu.sg/~a0120575/upload.php");
		fileText.setText("/mnt/sdcard/kate/renren.mp4");
		button.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				uploadFile = new UploadFile(MainActivity.this, fileText
						.getText().toString(), editText.getText().toString());
				uploadFile.start();
				// new upLoad().start();
			}
		});
		download.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				Intent intent = new Intent(MainActivity.this,
						ThreadDownloadDemo.class);
				startActivity(intent);
			}
		});
		response.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				new Thread(){

					@Override
					public void run() {
						ServerCommunicateUtil serverCommunicateUtil=new ServerCommunicateUtil();
						System.out.println("Status:"+serverCommunicateUtil.getVideostatus(1, 15));
						Toast.makeText(MainActivity.this, 
								"Status:"+serverCommunicateUtil.getVideostatus(1, 15),
								Toast.LENGTH_LONG).show(); 
					}
					
				}.start();
			}
		});
	}
}
